<?php

namespace app\api\controller;


use app\common\controller\Api;

use app\api\model\group\GroupNotice as GroupNoticeModel;


/**
 * 抱团公告接口
 */
class Groupnotice extends Api
{
    protected $noNeedRight = ['*'];


    //列表
    public function lists()
    {
        $group_id = input('group_id',0);

        $list = GroupNoticeModel::where(['group_id'=>$group_id])->order('createtime desc')->select();

        $this->success('',$list);
    }


    //添加
    public function add()
    {
        $group_id = input('group_id',0);
        $notice = input('notice',0);

        $notice_model = new GroupNoticeModel();

        $data = [
            'group_id'=>$group_id,
            'notice'=>$notice
        ];

        $res = $notice_model->save($data);

        if ($res){
            $this->success('添加成功');
        } else {
            $this->error('添加失败');
        }
    }

    //编辑
    public function edit()
    {
        $id = input('id',0);
        $notice = input('notice',0);

        $notice_model = new GroupNoticeModel();

        $data = [
            'notice'=>$notice
        ];

        $res = $notice_model->save($data,['id'=>$id]);

        if ($res){
            $this->success('编辑成功');
        } else {
            $this->error('编辑失败');
        }
    }

    //详情
    public function info()
    {
        $id = input('id',0);

        $info = GroupNoticeModel::get($id);

        $this->success('',$info);
    }

    //删除
    public function del()
    {
        $id = input('id',0);

        $info = GroupNoticeModel::get($id);
        $info->delete();

        $this->success('');
    }

}